import 'package:native_dart_package/http/request/exception/api_exception.dart';
import 'package:yt_devops/configs.dart';
import 'package:yt_devops/services/predicates.dart';

class SiteServices {
  /// 获取站点数量
  Future getSitesNum(
    params, {
    bool Function(ApiException)? onError,
  }) {
    return Configs.httpClient
        .get('$oss/appSite/siteNum', queryParameters: params, onError: onError);
  }

  /// 获取站点列表
  Future getSitesList(
    params, {
    bool Function(ApiException)? onError,
  }) {
    return Configs.httpClient
        .get('$oss/appSite/list', queryParameters: params, onError: onError);
  }

  /// 获取站点信息
  Future getSiteDetail(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
      '$oss/appSite/detail',
      queryParameters: params,
    );
  }

  /// 编辑站点信息
  Future editSiteInfo(params, {bool Function(ApiException)? onError}) {
    // Map<String, dynamic> headers = Map();
    //   headers['Content-Type'] = "application/x-www-form-urlencoded";

    return Configs.httpClient
        .put('$oss/appSite/edit', data: params, onError: onError);
  }

  /// 从工单页面创建站点信息
  Future createSite(params, {bool Function(ApiException)? onError}) {
    // Map<String, dynamic> headers = Map();
    //   headers['Content-Type'] = "application/x-www-form-urlencoded";

    return Configs.httpClient.post('$oss/installationWorkOrder/createSite',
        data: params, onError: onError);
  }

  /// 创建站点信息
  Future createNewSite(params, {bool Function(ApiException)? onError}) {
    // Map<String, dynamic> headers = Map();
    //   headers['Content-Type'] = "application/x-www-form-urlencoded";
    return Configs.httpClient
        .post('$system/site/create', data: params, onError: onError);
  }

  /// 获取站点概况统计数据
  Future getSiteStatistics(params) {
    return Configs.httpClient.get(
      '$oss/site/monitor/overview/app/statistics',
      queryParameters: params,
    );
  }

  /// 获取站点概况-天气
  Future getSiteWeather(params) {
    return Configs.httpClient.get(
      '$uc/site/app/weather',
      queryParameters: params,
    );
  }

  /// 获取站点-根据站点获取各个单元的设备统计数
  Future getSiteDeviceSummaryModel(params) {
    params.putIfAbsent('isConfine', () => 0);
    return Configs.httpClient.get(
      '$iot/device/summary',
      queryParameters: params,
    );
  }

  /// 获取站点-市电电价
  Future getSiteMains(params) {
    return Configs.httpClient.get(
      '$oss/site/mains/app/pageQuery',
      queryParameters: params,
    );
  }

  /// 获取站点-光伏上网电价
  Future getSiteInternet(params) {
    params['type'] = 0;
    return Configs.httpClient.get(
      '$oss/site/internet/app/pageQuery',
      queryParameters: params,
    );
  }

  /// 获取站点-储能放电电价
  Future getStoreDischarge(params) {
    params['type'] = 1;
    return Configs.httpClient.get(
      '$oss/site/internet/app/pageQuery',
      queryParameters: params,
    );
  }

  /// 获取站点-充电电价
  Future getSiteCharge(params) {
    return Configs.httpClient.get(
      '$oss/site/charge/app/pageQuery',
      queryParameters: params,
    );
  }

  /// 获取站点-市电电价详情
  Future getSiteMainsDetail(params) {
    return Configs.httpClient.get(
      '$oss/site/mains/app/getInfo',
      queryParameters: params,
    );
  }

  /// 获取站点-上网电价详情
  Future getSiteInternetDetail(params) {
    return Configs.httpClient.get(
      '$oss/site/internet/app/getInfo',
      queryParameters: params,
    );
  }

  /// 获取站点-充电电价详情
  Future getSiteChargeDetail(params) {
    return Configs.httpClient.get(
      '$oss/site/charge/app/getInfo',
      queryParameters: params,
    );
  }

  /// 站点统计数据
  Future getSiteDataStatistics(params) {
    return Configs.httpClient.get(
      '$oss/site/index/dataStatistics',
      queryParameters: params,
    );
  }

  /// 站点统计数据 新改动20240320
  Future getSiteDataStatisticsNew(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/monitor/overview/getOverviewData',
        queryParameters: params, onError: onError);
  }

  /// 站点统计数据 朱鹏修改20240411
  Future getSiteAllDayPower(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/collectionData/allDayPower',
        queryParameters: params, onError: onError);
  }

  /// 数据统计站点收益,首页统计也可以用20240515
  Future getSiteOverviewGainsStatistics(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get(
        '$oss/site/monitor/overview/siteOverviewGainsStatistics',
        queryParameters: params,
        onError: onError);
  }

  //安装商列表
  Future getInstallProvideList(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$uc/customerUser/serviceProvider/page',
        queryParameters: params, onError: onError);
  }

  // 站点概览-能源流动图
  Future getSiteEnergyFlow(params) {
    return Configs.httpClient
        .get('$oss/topologicalGraph/logicalViewPower', queryParameters: params);
  }

  ///首页储能统计概览
  Future getEsOverviewStatistics(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/index/app/esOverviewStatistics',
        queryParameters: params, onError: onError);
  }

  ///首页储能电量统计
  Future getEsPowerStatisticsChart(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/index/app/esOverviewHistogram',
        queryParameters: params, onError: onError);
  }

  ///首页储能排名
  Future getEsPowerStatisticsRank(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/index/app/esOverViewSiteSort',
        queryParameters: params, onError: onError);
  }

  ///站点设备监视顶不tab
  Future getMonitorDeviceTab(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/monitor/device/productTypeCount',
        queryParameters: params, onError: onError);
  }

  ///获取所有储能站点当天功率
  Future getEsDayPower(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$oss/site/index/es', queryParameters: params, onError: onError);
  }

  ///获取储能站点下储能单元
  Future getEsListStatistics(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$oss/site/index/app/getEsListStatistics',
        queryParameters: params, onError: onError);
  }

  ///添加站点收藏
  Future addFavorite(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$uc/site/collect', data: params, onError: onError);
  }

  ///取消站点收藏
  Future cancelFavorite(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .delete('$uc/site/collect', data: params, onError: onError);
  }

  ///获取站点视频监控信息
  Future getSiteVideoMonitorInfo(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$uc/site/videoMonitor',
        queryParameters: params, onError: onError);
  }

  ///获取站点视频监控信息
  Future updateSiteVideoMonitorInfo(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$uc/site/videoMonitor', data: params, onError: onError);
  }

  ///获取视频监控厂家下拉列表
  Future getVideoMonitorFactoryList({bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/site/videoMonitor/factoryList', onError: onError);
  }

  ///获取站点视频监控信息
  Future getVideoMonitorAppList({bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/site/videoMonitor/appList', onError: onError);
  }

  ///储能单元设备列表
  //   GET {{iot}}/es/unitDeviceList
  //   接口ID：172297449
  //   接口地址：https://app.apifox.com/link/project/3172698/apis/api-172297449
  Future getUnitDeviceList(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$iot/es/unitDeviceList',
        queryParameters: params, onError: onError);
  }

  ///  保存储能单元
//  POST {{iot}}/es/unitDeviceList
//  接口ID：172494763
//  接口地址：https://app.apifox.com/link/project/3172698/apis/api-172494763
  Future saveUnitDeviceList(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$iot/es/unitDeviceList', data: params, onError: onError);
  }

  ///  储能单元可选设备列表
//  GET {{iot}}/es/optionalDeviceList
//  接口ID：172257515
//  接口地址：https://app.apifox.com/link/project/3172698/apis/api-172257515
  Future getUnitOptionalDeviceList(params,
      {bool Function(ApiException)? onError}) {
    return Configs.httpClient.post('$iot/es/optionalDeviceList',
        queryParameters: params, onError: onError);
  }

  /// 获取参数设置
  Future getParameterSetting(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$uc/site/parameterSetting',
        queryParameters: params, onError: onError);
  }

  /// 获取货币单位列表
  Future getMonetaryUnit({bool Function(ApiException)? onError}) {
    return Configs.httpClient.get('$uc/site/monetaryUnit', onError: onError);
  }

  /// 设置参数设置
  Future setParameterSetting(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .put('$uc/site/parameterSetting', data: params, onError: onError);
  }

  /// 设置告警推送
  Future setSiteAlarmPush(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .post('$uc/site/alarmPush', data: params, onError: onError);
  }

  /// 获取告警推送
  Future getSiteAlarmPush(params, {bool Function(ApiException)? onError}) {
    return Configs.httpClient
        .get('$uc/site/alarmPush', queryParameters: params, onError: onError);
  }
}
